package com.kpx.app.wigdet;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.kpx.app.R;

/**
 * 正常的提示操作
 * 陈聪
 */
public class AMentionDialog extends BaseDialog implements View.OnClickListener {

    private OnPositiveButtonClickListener onPositiveButtonClickListener;
    private OnNegativeButtonClickListener onNegativeButtonClickListener;
    private TextView tvTitle;
    private Button btnPositive;
    private Button btnNegative;
    private TextView txtmg;

    public AMentionDialog(Context context) {
        super(context);
        setContent();
    }

    public AMentionDialog(Context context, String title, OnPositiveButtonClickListener onPositiveButtonClickListener, OnNegativeButtonClickListener onNegativeButtonClickListener) {
        super(context);
        setContent();
        setTitle(title);
        setOnPostitiveButtonClickListener(onPositiveButtonClickListener);
        setOnNegativeButtonClickListener(onNegativeButtonClickListener);
    }

    public AMentionDialog(Context context, String negativeButtonText, String positiveButtonText, String title, String mg, OnNegativeButtonClickListener onNegativeButtonClickListener) {
        super(context);
        setContent();
        setTitle(TextUtils.isEmpty(title) ? "温馨提示" : title);
        setMg(mg);
        setPositiveButtonText(TextUtils.isEmpty(positiveButtonText) ? "取消" : positiveButtonText);
        setNegativeButtonText(TextUtils.isEmpty(positiveButtonText) ? "确定" : negativeButtonText);
        setOnPostitiveButtonClickListener(new OnPositiveButtonClickListener() {
            @Override
            public void onPositiveButtonClick() {
                dismiss();
            }
        });
        setOnNegativeButtonClickListener(onNegativeButtonClickListener);
    }

    public AMentionDialog(Context context, String title) {
        super(context);
        setTitle(title);
        setContent();
    }

    private void setContent() {
        setContentView(R.layout.dialog_a_mention_layout);
        tvTitle = (TextView) findViewById(R.id.title);
        txtmg = (TextView) findViewById(R.id.mg);
        btnPositive = (Button) findViewById(R.id.btnPositive);
        btnNegative = (Button) findViewById(R.id.btnNegative);

        btnPositive.setOnClickListener(this);
        btnNegative.setOnClickListener(this);
    }

    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    public void setMg(String mg) {
        txtmg.setText(mg);
    }

    public void setButtonTextColor(int resId) {
        if (null != btnPositive) {
            btnPositive.setTextColor(resId);
        }
        if (null != btnNegative) {
            btnNegative.setTextColor(resId);
        }
    }

    public void setPositiveButtonText(String text) {
        btnPositive.setText(text);
    }

    public void setNegativeButtonText(String text) {
        btnNegative.setText(text);
    }

    /**
     * 确定
     */
    public void setOnPostitiveButtonClickListener(OnPositiveButtonClickListener listener) {
        this.onPositiveButtonClickListener = listener;

    }

    /**
     * 取消
     */
    public void setOnNegativeButtonClickListener(OnNegativeButtonClickListener listener) {
        this.onNegativeButtonClickListener = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnPositive:
                if (onPositiveButtonClickListener != null)
                    onPositiveButtonClickListener.onPositiveButtonClick();
                break;
            case R.id.btnNegative:
                if (onNegativeButtonClickListener != null) {
                    onNegativeButtonClickListener.oNegativeButtonClick(this);
                }
                break;
        }
    }

    /**
     * 确定监听器
     */
    public interface OnPositiveButtonClickListener {
        void onPositiveButtonClick(); // 点击确定按钮
    }

    /**
     * 取消监听器
     */
    public interface OnNegativeButtonClickListener {
        void oNegativeButtonClick(AMentionDialog dialog); // 点击取消按钮
    }
}
